<?php
/**
 * Administrator Form
 *
 * @category   Cms
 * @package    Cms_Form
 */
class Cms_Form_Administrator_Administrator_Form extends BIS_Form_Abstract
{
    public function init()
    {
        $this->addElementPrefixPath('Cms_Decorator',
                            	     APPLICATION_PATH . '/modules/cms/models/decorator/',
                            	    'decorator');
        // add path to custom validators
        $this->addElementPrefixPath(
            'Cms_Validate',
            APPLICATION_PATH . '/modules/cms/models/validate/',
            'validate'
        );

        $this->setMethod('post');
        $this->setAction('');
        $this->setModel(new Cms_Model_Administrator());

        $administratorGroups = $this->getModel()->getAdministratorGroups();
        $groups = array();
        $groups[NULL] = ' --- Select Group --- ';
        foreach($administratorGroups as $administratorGroup) {
            $groups[$administratorGroup->adminGroupId] = $administratorGroup->name;
        }

        $this->addElement('hidden', 'adminId', array(
            'filters'    => array('StringTrim'),
            'required' => true,
            'decorators' => array('viewHelper')
        ));

        $this->addElement('text', 'username', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                array('StringLength', true, array(3, 128)),
                array('UniqueUsername', false, array(new Cms_Model_Administrator()))
            ),
            'required'   => true,
            'label'      => 'Username'
        ));

        $this->addElement('text', 'surname', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alpha',
                array('StringLength', true, array(3, 128))
            ),
            'required'   => true,
            'label'      => 'Surname'
        ));

        $this->addElement('text', 'otherNames', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alpha',
                array('StringLength', true, array(3, 128))
            ),
            'required'   => true,
            'label'      => 'Other Names'
        ));

        $this->addElement('text', 'email', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array('EmailAddress',
                array('StringLength', true, array(3, 128)),
                array('UniqueEmail', false, array(new Cms_Model_Administrator())),
            ),
            'label' => 'Email'
        ));

        $this->addElement('select', 'adminGroupId', array(
            'label' => 'Administrator Group',
            'required' => true,
            'multiOptions' => $groups
        ));

        $this->addElement('password', 'password', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', true, array(6, 128))
            ),
            'required'   => true,
            'label'      => 'Password'
        ));

        $this->addElement('password', 'passwordVerify', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
               'PasswordVerification'
            ),
            'required'   => true,
            'label'      => 'Confirm Password'
        ));

        $this->addElement('select', 'status', array(
            'label' => 'Status',
            'required' => true,
            'multiOptions' => array(1 => "Enabled", 0 => "Disabled")
        ));
        
        $this->setElementDecorators(array(
            'ViewHelper',
            'FormElementsErrors',
             array(array('data' => 'HtmlTag'),  array('tag' =>'td')),
              'FormElementsLabel',
            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
            ),
            array(
                'adminId'
            ),
            false
         );

        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'table', 'class'=> 'form')),
            'Form'
        ));

    }
}